<?php
include("../lib/db.lib");
include("../lib/std.lib");


//Create related ones

$p_id = $_GET["id"];

$url="Topics/".$p_id;
$url = preg_replace("/\/\//","/",$url);


$str = "";

$file_id0 = "/".$_GET["id"];
$file_id0 = preg_replace("/\/\//","/",$file_id0);

$file_id = preg_replace("/\//","_",$file_id0);


if(file_exists("./cache/$file_id"))
{
	$fh=fopen("./cache/$file_id","r");
	while(!feof($fh)) $str.=fread($fh, 200000);
	fclose($fh);
}
else
{
	$fh=fopen("http://www.xys.org/xys/$file_id0","r");
	while(!feof($fh)) $str.=fread($fh, 200000);
	fclose($fh);

//	$fh=fopen("./cache/$file_id","w");
//	fwrite($fh, $str);
//	fclose($fh);

}


if($_GET["no_encode"] || 1){
	$str = iconv("GBK","UTF-8",$str);
	//$str=mb_convert_encoding($str,"UTF-8","GBK");
	//$str = base64_encode($str);
	echo $str;
	exit(0);
}

$str = iconv("GBK","UTF-8",$str);
$str = base64_encode($str);
/*
echo $str;
exit(0);
*/

/// Code stops here.


$pass=1;
$newstr = chr($pass);
for($i=0;$i<strlen($str);$i++){
	$newstr.= chr( (ord(substr($str,$i,1)) + ($i+1)*($i+1) - 43 +$pass) % 82+43);
	//$newstr.= chr( ((ord(substr($str,$i,1))  - 43 +$pass) % 82) +43);
}
echo $newstr;

?>
